package com.demo.window.insets

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowInsetsCompat
import androidx.viewbinding.ViewBinding
import com.demo.window.insets.databinding.TitleCommBinding
import com.liulu.window.insets.immerse

/**
 * https://blog.csdn.net/jingzz1/article/details/105909040
 * @auth: LiuLu
 * @date: 2025/4/9 21:10
 */
abstract class BaseBindingActivity2<VB : ViewBinding>(val block: (LayoutInflater, ViewGroup, Boolean) -> VB) :
    AppCompatActivity() {

    lateinit var mTitleBinding: TitleCommBinding
//    lateinit var mViewBinding: VB

    @get:JvmName("mBinding")
    val mViewBinding by lazy { block(layoutInflater, mTitleBinding.root, true) }

    //    abstract fun initViewBinding(): VB
    open fun initWindowInsets(v: View, insets: WindowInsetsCompat) {}
    open fun initData() {}

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mTitleBinding = TitleCommBinding.inflate(layoutInflater)
        setContentView(mTitleBinding.root)
//        mViewBinding = initViewBinding()
        immerse(listener = { v, insets ->
            initWindowInsets(v, insets)
            insets
        })
        initData()
    }

    fun setTitleVisible(visible: Int = View.GONE) {
        mTitleBinding.titleLayout.visibility = visible
    }

    fun setTitleName(titleName: String?) {
        mTitleBinding.titleName.text = titleName
    }
}